<?php
session_start();
include("../include/config.inc.php");

$todo=$_REQUEST["todo"];
if(isset($todo) && $todo=="todo"){
	$mobile = $_POST['mobile'];
	$smscode = $_POST['smscode'];
	$password = $_POST['password'];
	$configpass = $_POST['configpass'];
	$code = $_POST['code'];
	$verify = $_SESSION['session_verify'];
	$sms = $_SESSION['session_smscode'];
	
	if($code==""){
		echo "<script>alert('请输入验证码！');history.back(-1);</script>";
		exit;
	}
	if($code<>$verify){
		echo "<script>alert('请输入正确的验证码！');history.back(-1);</script>";
		exit;
	}
	if($mobile==""){
		echo "<script>alert('请输入手机号码！');history.back(-1);</script>";
		exit;
	}
	if($smscode==""){
		echo "<script>alert('请输入手机短信验证码！');history.back(-1);</script>";
		exit;
	}
	if($smscode<>$sms){
		echo "<script>alert('手机短信验证码输入不正确！');history.back(-1);</script>";
		exit;
	}
	if($password==""){
		echo "<script>alert('请输入6-20位的密码！');history.back(-1);</script>";
		exit;
	}
	if($configpass==""){
		echo "<script>alert('请确认密码！');history.back(-1);</script>";
		exit;
	}
	if($password<>$configpass){
		echo "<script>alert('两次密码输入不一致！');history.back(-1);</script>";
		exit;
	}
	if(CountByKey(tablepre."member","member_mobile",$mobile))
    {
		PhpBox("该手机号码已经存在，请使用新号码或找回密码！");
		GotoPage("h");
		exit;  
	}
	$ip=getIP();
	$time=time();
	$member_name="wycn_yx_".$time;
	$member_passwd=md5($password);
	$member_mobile=$mobile;
	$member_mobile_bind='1';
	$member_login_num='1';
	$member_time=$time;
	$member_login_time=$time;
	$member_old_login_time=$time;
	$member_login_ip=$ip;
	$member_old_login_ip=$ip;
	$member_points='20';
	$member_old_login_time=$time;
	$member_provinceid='19';
	$member_areainfo='广东省';
	$sql="insert into ".tablepre."member(member_name,member_passwd,member_mobile,member_mobile_bind,member_login_num,member_time,member_login_time,member_old_login_time,member_login_ip,member_old_login_ip,member_points,member_provinceid,member_areainfo)values
	
	('$member_name','$member_passwd','$member_mobile','$member_mobile_bind','$member_login_num','$member_time','$member_login_time','$member_old_login_time','$member_login_ip','$member_old_login_ip','$member_points','$member_provinceid','$member_areainfo')";	
	$db->query($sql);
	if(!$db->error())
	{
		echo "<script>alert('注册成功！');location.href='login.php';</script>";
		$db->close();
		exit;
	}
	else
	{
		echo "<script>alert('数据库出错，请重新注册。');location.href='register.php';</script>";		
		$db->close();
		exit;
	}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no" />
<meta name="format-detection" content="telephone=no" />
<title>注册会员</title>
<link rel="stylesheet" type="text/css" href="../css/login.css">
<script type="text/javascript" src="../js/clientwidth.js"></script>
<script type="text/javascript" src="../js/jquery.js"></script>
<script language="javascript">
	function get_mobile_code(){
        $.post('sms.php', {mobile:jQuery.trim($('#mobile').val()),send_code:jQuery.trim($('#code').val()),smstype:jQuery.trim($('#smstype').val())}, function(msg) {
            alert(jQuery.trim(unescape(msg)));
			if(msg=='短信发送成功'){
				RemainTime();
			}
        });
	};
	var iTime = 59;
	var Account;
	function RemainTime(){
		document.getElementById('zphone').disabled = true;
		var iSecond,sSecond="",sTime="";
		if (iTime >= 0){
			iSecond = parseInt(iTime%60);
			iMinute = parseInt(iTime/60)
			if (iSecond >= 0){
				if(iMinute>0){
					sSecond = iMinute + "分" + iSecond + "秒";
				}else{
					sSecond = iSecond + "秒";
				}
			}
			sTime=sSecond;
			if(iTime==0){
				clearTimeout(Account);
				sTime='获取手机验证码';
				iTime = 59;
				document.getElementById('zphone').disabled = false;
			}else{
				Account = setTimeout("RemainTime()",1000);
				iTime=iTime-1;
			}
		}else{
			sTime='没有倒计时';
		}
		document.getElementById('zphone').value = sTime;
	}	
</script>
</head>

<body>
<header class="header" style="display:block;"><span class="goback"></span>注册会员<span class="close"></span></header>
<form id="login-form" action="" method="post">
<input name="todo" type="hidden" value="todo">
<input name="smstype" id="smstype" type="hidden" value="register">
<section class="loginpage">
	<div class="loginlogo"><img src="../images/logo.png" /></div>
	<div class="loginform">
		<div class="input-container">
            <input id="mobile" name="mobile" type="text" placeholder="请输入手机号码" maxlength="11" style="border-radius:5px 5px 0px 0px;background-position:0px 3px;">
        </div>
		<div class="input-container">
            <input id="smscode" name="smscode" type="text" placeholder="请输入短信验证码" maxlength="6" style="border-radius:0px 0px 0px 0px;border-top:none;border-bottom:none;">
            <span class="code-box"><input id="zphone" type="button" value=" 获取手机验证码 " onClick="get_mobile_code();" class="btn"></span>
        </div>
		<div class="input-container">
            <input id="password" name="password" type="password" placeholder="请输入6-20位的密码" minlength="6" maxlength="20" style="border-radius:0px 0px 0px 0px;">
        </div>
		<div class="input-container">
            <input id="configpass" name="configpass" type="password" placeholder="请确认密码" minlength="6"  maxlength="20" style="border-radius:0px;border-top:none;">
        </div>
		<div class="input-container">
            <input id="code" name="code" type="text" placeholder="请输入验证码" maxlength="4" style="border-radius:0px 0px 5px 5px;border-top:none;">
            <span class="code-box"><img id="imgCode" src="../include/verify.php" alt="请输入验证码" style="border-radius:0px 0px 5px 0px;"></span>
        </div>
	</div>
	<div class="notice"></div>
	<div class="input-submit"><input name="s" type="submit" class="sub-input" value="登 录" /></div>
	<div class="quick-nav">
    	<a href="findpassword.php" class="findpwd">找回密码</a>
        <a href="loginbysms.php" class="quickReg">短信登陆</a>
    </div>
    <div class="quick-login">
        <h4>其他登录方式</h4>
        <a href="login.php"><i class="icon icon-user"></i><br>账号</a>
		<a href="https://graph.qq.com/oauth2.0/authorize?response_type=code&client_id=101401700&redirect_uri=http%3a%2f%2ft.wycn.com%2f/user/qqlogin.php&state=1&scope=get_user_info"><i class="icon icon-qq"></i><br>QQ</a>
        <a href="https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxa4cf994a9d00afb8&redirect_uri=http%3A%2F%2Fwx.wycn.com%2Fzt%2Fcut%2FUserInfo.php&response_type=code&scope=snsapi_userinfo&state=1&connect_redirect=1#wechat_redirect"><i class="icon icon-wx"></i><br>微信</a>
    </div>
</section>
</form>
<script>
if (document.body.clientWidth > 500) {
	$('.loginpage').css({
		width: 500,
		margin: '0 auto',
	});
}
</script>
</body>
</html>